package com.augurit.common.system.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.common.base.extmodel.BasicCombo;
import com.augurit.common.entity.AcServer;
import com.augurit.common.system.util.OrgUtils;
import com.augurit.common.system.web.org.form.AcServerForm;


public class AcServerConverter {
	
	public static void convertToEntity(AcServerForm form, AcServer entity){
		if(form != null && entity != null){

			if(form.getServId() != null)
				entity.setServId(form.getServId());
			
			if(form.getServName() != null && form.getServName().trim().length() > 0)
				entity.setServName(form.getServName());
			
			if(form.getServIp() != null && form.getServIp().trim().length() > 0)
				entity.setServIp(form.getServIp());
			
			if(form.getServPort() != null && form.getServPort().trim().length() > 0)
				entity.setServPort(form.getServPort());
			
			if(form.getRemark() != null && form.getRemark().trim().length() > 0)
				entity.setRemark(form.getRemark());
		}
	}
	
	public static AcServerForm convertToForm(AcServer entity){
		if(entity != null){
			AcServerForm form = new AcServerForm();
			form.setServId(entity.getServId());
			form.setServName(entity.getServName());
			form.setServIp(entity.getServIp());
			form.setServPort(entity.getServPort());
			form.setRemark(entity.getRemark());
			return form;
		}else
			return null;	
	}
	
	public static List<AcServerForm> convertToFormList(List<AcServer> list){
		if(list != null && list.size() > 0){
			List<AcServerForm> result = new ArrayList();
			
			for(AcServer entity : list){
				result.add(convertToForm(entity));
			}
			
			return result;
		}else
			return null;
	}
	
	public static List<BasicCombo> convertToBasicCombo(List<AcServerForm> list, boolean allowBlank){
		List<BasicCombo> result = new ArrayList();
		
		if(allowBlank)
			result.add(BasicCombo.getBlankItem());

		if(list != null && list.size() > 0){
			for(AcServerForm form : list){
				BasicCombo combo = new BasicCombo();
				combo.setLabel(OrgUtils.convertAcServerInfoToString(form));
				combo.setValue(form.getServId().toString());
				result.add(combo);
			}
		}
		
		return result;
	}
}
